package com.study.example.gameserver.module.backpack.use.handler;

import com.sparrow.common.handler.Handler;
import com.study.example.gameserver.module.backpack.use.ItemUseContext;
import com.study.example.gameserver.module.backpack.use.ItemUseHandler;

import java.util.concurrent.ConcurrentHashMap;

public abstract class AbstractItemUseHandler implements Handler<ItemUseHandler, String> {

    private static ConcurrentHashMap<Integer, ItemUseWithStateHandler> withStateHandlerMap = new ConcurrentHashMap<>();

    public void handle(ItemUseContext context) {
    }

    public ItemUseWithStateHandler getHandler(int modelId, String useParam) {
        //缓存获取
        return withStateHandlerMap.computeIfAbsent(modelId, k -> createHandler(useParam));
    }

    public abstract ItemUseWithStateHandler createHandler(String useParam);

    public static void clearStateHandler() {
        withStateHandlerMap.clear();
    }

}
